package com.bub.pay.api.controller;

import com.bub.pay.core.entity.domain.SysRole;
import com.bub.pay.core.entity.dto.merchant.MerchantRoleAddPermDTO;
import com.bub.pay.core.entity.dto.merchant.MerchantRoleSelectDTO;
import com.bub.pay.core.entity.vo.merchant.MerchantRoleSelectVO;
import com.bub.pay.core.manager.merchant.MerchantRoleManager;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description 商户角色管理Controller
 * @Auhtor John
 */
@RestController
@RequestMapping("/merchant/roleManagement")
public class MerchantRoleManagementController {

    @Resource
    MerchantRoleManager merchantRoleManager;

    @PostMapping("/selectRoles")
    public Object selectMerchantRole(@RequestBody MerchantRoleSelectDTO dto){
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize());
        PageInfo<MerchantRoleSelectVO> pages = new PageInfo<>(merchantRoleManager.selectMerchantRole(dto));
        return pages;
    }

    @PostMapping("/insertRole")
    public Object insertRoleSelective(@RequestBody SysRole sysRole){
        return merchantRoleManager.insertRoleSelective(sysRole);
    }

    @PostMapping("/deleteRole")
    public Object deleteRoleByPrimaryKey(@RequestBody SysRole sysRole){
        return merchantRoleManager.deleteRoleByPrimaryKey(sysRole.getId());
    }

    @PostMapping("/updateRole")
    public Object updateRole(@RequestBody SysRole sysRole){
        return merchantRoleManager.updateRole(sysRole);
    }

//    @RequiresPermissions("merchant:roleManagement:getAll")
    @GetMapping("/allRoles")
    public Object allRoles(){
        return merchantRoleManager.allRoles();
    }


    @PostMapping("/getPermsOfRole")
    public Object getPermOfRole(@RequestBody SysRole sysRole){
        return merchantRoleManager.getPermOfRole(sysRole.getId());
    }

//    public Object getPermOfPlatform(){}

    @PostMapping("/setPerm4role")
    public Object setPermForRole(@Valid @RequestBody MerchantRoleAddPermDTO dto){
        return merchantRoleManager.setPermForRole(dto);
    }

    @PostMapping("getPermsOfRoleIsExist")
    public Object getPermOfRoleIsContains(@RequestBody SysRole sysRole){
        return merchantRoleManager.getPermsOfRoleIsContainsInPlatformAllPerms(sysRole.getId());
    }

}
